﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VersionComparer.UI
{
    public partial class XmlFragmentsControl : UserControl, IContainedControl
    {
        public XmlFragmentsControl()
        {
            InitializeComponent();
            xmlFramentViewerControl1.Scrolled += xmlFramentViewerControl1_Scrolled;
            xmlFramentViewerControl2.Scrolled += xmlFramentViewerControl2_Scrolled;
            xmlFramentViewerControl2.Scroll += xmlFramentViewerControl2_Scroll;
            xmlFramentViewerControl1.Scroll += xmlFramentViewerControl1_Scroll;

        }

        bool enableScroll1 = true;
        bool enableScroll2 = true;
        void xmlFramentViewerControl2_Scrolled(object sender, EventArgs e)
        {
            if (!cbLockScroll.Checked || !enableScroll2)
                return;
            enableScroll1 = false;
            xmlFramentViewerControl1.ScrollTo(xmlFramentViewerControl2.HorizontalScrollPos, xmlFramentViewerControl2.VerticalScrollPos);
            enableScroll1 = true;
        }

        void xmlFramentViewerControl1_Scroll(object sender, ScrollEventArgs e)
        {
            
        }

        void xmlFramentViewerControl2_Scroll(object sender, ScrollEventArgs e)
        {
            
        }

        void xmlFramentViewerControl1_Scrolled(object sender, EventArgs e)
        {
            if (!cbLockScroll.Checked || !enableScroll1)
                return;
            enableScroll2 = false;
            xmlFramentViewerControl2.ScrollTo(xmlFramentViewerControl1.HorizontalScrollPos, xmlFramentViewerControl1.VerticalScrollPos);
            enableScroll2 = true;
        }
        

        private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
        {

        }

        public string FragmentText1
        {
            get
            {
                return xmlFramentViewerControl1.FragmentText;
            }
            set
            {
                xmlFramentViewerControl1.FragmentText = value;
            }
        }

        public string FragmentText2
        {
            get
            {
                return xmlFramentViewerControl2.FragmentText;
            }
            set
            {
                xmlFramentViewerControl2.FragmentText = value;
            }
        }

        string IContainedControl.Text
        {
            get {

                return Resources.Resources.XmlFragmentsCaption;
            }
        }




        public void Close(bool acceptChanges)
        {
        }
    }
}
